<!-- MAIN CONTENT -->
<div id="content">
    <div smart-include="app/yksensor/views/sub-header.tpl.html"></div>
    <!-- widget grid -->
    <section widget-grid id="widget-grid">

        <div class="row">
            <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div jarvis-widget data-widget-editbutton="false" data-widget-color="darken">
                    <header>
                     <h2>设备管理</h2>
                    </header>
                    <div>
                        <div class="widget-body-toolbar" ng-show="device_manage">
                            <div class="row">
                                 <div class="pull-left margin-right-20">
                                    <a class="btn btn-labeled btn-primary" data-toggle="modal" data-target="#addModal"> <span class="btn-label"><i class="glyphicon glyphicon-plus"></i></span>添加设备 </a>
                                </div>
                            </div>
                        </div>
                        <div class="widget-body no-padding">

                            <div class="table-responsive">

                                <table class="table table-bordered table-striped table-condensed table-hover smart-form">
                                    <thead>
                                        <tr>
                                            <th ng-show="device_manage">操作</th>
                                            <th>序号</th>
                                            <th>客户名称</th>
                                            <th>设备名称</th>
                                            <th>设备编号</th>
                                            <th>设备端口</th>
                                            <th>设备类型</th>
                                            <th>绑定项目</th>
                                            <th>SIM卡号码</th>
                                            <!-- <th>注册状态</th>
                                            <th>锁定设备</th> -->
                                            <th>所属区域</th>
                                            <!-- <th>地理位置</th> -->
                                            <th>设备状态</th>
                                            <!-- <th>备注</th> -->
                                            <th>参数设置</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr ng-repeat="item in datas">
                                            <td ng-show="device_manage">
                                              <button class='btn btn-xs btn-default' uib-tooltip='编辑' tooltip-append-to-body='true' ng-click="showEditDevice(item)"  ng-disabled="observer"><i class='fa fa-pencil'></i></button>
                                              <button class='btn btn-xs btn-default' uib-tooltip='删除' tooltip-append-to-body='true' ng-click="showDelDialog(item)" ng-disabled="observer"><i class='fa fa-times'></i></button>
                                            </td>
                                            <td>{{item.id}}</td>
                                            <td>{{item.clientname}}</td>
                                            <td>{{item.devicename}}</td>
                                            <td>{{item.deviceid}}</td>
                                            <td>{{item.port}}</td>
                                            <td>{{item.type == 1 ? '流量计' :(item.type == 2 ? '液位计' : (item.type == 3 ? '温度计' : '其他')) }}</td>
                                            <td>{{item.proname}}</td>
                                            <td>{{item.sim}}</td>
                                            <!-- <td>{{item.register == 0 ? '未注册' :(item.register == 1 ? '已注册' : '') }}</td>
                                            <td>{{item.lockdevice == 0 ? '未锁定' :(item.lockdevice == 1 ? '已锁定' : '')}}</td> -->
                                            <td>{{item.zone}}</td>
                                            <!-- <td>{{item.pos}}</td> -->
                                            <td class="text-center"><span class="{{item.status_tag | status_tag}}">生效</span></td>
                                            <!-- <td>{{item.remarks}}</td> -->
                                            <td>
                                                <button class='btn btn-xs btn-default' uib-tooltip='参数设置' tooltip-append-to-body='true' ng-click="showSetDialog(item)" ng-disabled="observer"><i class='fa fa-send '>参数设置</i></button>
                                                <!-- <button class='btn btn-xs btn-default' uib-tooltip='下发查询' tooltip-append-to-body='true' ng-click="showQueryDialog(item.deviceid)"><i class='fa fa-send '>下发查询</i></button> -->
                                             </td>
                                        </tr>
                                    </tbody>
                                </table>
                               
                            </div>
                            <div class="dt-toolbar-footer">
                                <tm-pagination conf="paginationConf"></tm-pagination>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </article>
        </div>
    </section>
    <!-- 设备绑定 -->
    <div class="row" ng-show="device_manage" style="display:none;">
        <h1 class="margin-bottom-30 margin-top-20 clearfix">
            <div class="col-sm-2">
                <h6>设备编号：</h6>
                <select class="form-control" ng-model="bindObj.did" id="device-id">
                    <option value="0" selected="selected">请选择设备编号</option>
                    <option ng-repeat="device in devices" value="{{device.id}}">{{device.deviceid}}</option>
                </select>
            </div>
            <div class="col-sm-2">
                <h6>项目：</h6>
                <select class="form-control" ng-model="bindObj.pid">
                    <option value="0" selected="selected">请选择项目名称</option>
                    <option ng-repeat="project in projects" value="{{project.id}}">{{project.name}}</option>
                </select>
            </div>
            <div class="col-sm-2">
                <button class="btn btn-primary" style="margin-top:40px;" id="m1" ng-click="bind_dialog()"><i class="glyphicon glyphicon-link"></i>&nbsp;绑定</button>
            </div>
        </h1>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">添加设备</h4>
                </div>
                <div class="modal-body">

                    <form id="smart-form-register" class="smart-form" data-smart-registration-form ng-submit="insertdata()">
                        <fieldset class="row">
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">客户名称</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="insert.clientname">
                                </label>
                            </section>

                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备名称</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="insert.devicename">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备编号</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="insert.deviceid">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备端口</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="insert.port">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备类型</label>
                                <label class="select">
                                    <select name="" id="" ng-model="insert.type" required="required">
                                        <option ng-repeat="type in types" value="{{type.id}}">{{type.name}}</option>
                                    </select>
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">绑定项目</label>
                                <label class="select">
                                    <select name="" id="" ng-model="insert.projectid" required="required">
                                        <option ng-repeat="project in projects" value="{{project.id}}">{{project.name}}</option>
                                    </select>
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">SIM卡号码</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="insert.sim">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">所属区域</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="insert.zone">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">地理位置</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="insert.pos" placeholder="正确格式：经度|伟度">
                                </label>
                            </section>
                            <!-- <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">注册状态</label>
                                <label class="select">
                                    <select name="" id="" ng-model="insert.register">
                                        <option value="0">未注册</option>
                                        <option value="1">已注册</option>
                                    </select>
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">锁定设备</label>
                                <label class="select">
                                    <select name="" id="" ng-model="insert.lockdevice">
                                        <option value="0">未锁定</option>
                                        <option value="1">已锁定</option>
                                    </select>
                                </label>
                            </section> -->
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备状态</label>
                                <label class="select">
                                    <select name="" id="" ng-model="insert.status_tag" required="required">
                                        <option value="生效">生效</option>
                                        <option value="失效">失效</option>
                                    </select>
                                </label>
                            </section>
                            <!-- <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">备注</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="insert.remarks">
                                </label>
                            </section> -->
                           
                        </fieldset>

                        <footer>

                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                关闭
                            </button>
                            <button type="submit" class="btn btn-primary">
                                提交
                            </button>

                        </footer>
                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">编辑设备</h4>
                </div>
                <div class="modal-body">

                    <form id="smart-form-register" class="smart-form" data-smart-registration-form ng-submit="updatedata()">
                        <fieldset class="row">
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">客户名称</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="editdata.clientname">
                                </label>
                            </section>

                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备名称</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="editdata.devicename">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备编号</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="editdata.deviceid">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备端口</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="editdata.port">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备类型</label>
                                <label class="select">
                                    <select name="" id="" ng-model="editdata.type" required="required">
                                        <option ng-repeat="type in types" value="{{type.id}}">{{type.name}}</option>
                                    </select>
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">绑定项目</label>
                                <label class="select">
                                    <select name="" id="" ng-model="editdata.projectid" required="required">
                                        <option ng-repeat="project in projects" value="{{project.id}}">{{project.name}}</option>
                                    </select>
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">SIM卡号码</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="editdata.sim">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">所属区域</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="editdata.zone">
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">地理位置</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="editdata.pos" placeholder="正确格式：经度|伟度">
                                </label>
                            </section>
                            <!-- <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">注册状态</label>
                                <label class="select">
                                    <select name="" id="" ng-model="editdata.register">
                                        <option value="0">未注册</option>
                                        <option value="1">已注册</option>
                                    </select>
                                </label>
                            </section>
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">锁定设备</label>
                                <label class="select">
                                    <select name="" id="" ng-model="editdata.lockdevice">
                                        <option value="0">未锁定</option>
                                        <option value="1">已锁定</option>
                                    </select>
                                </label>
                            </section> -->
                            <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">设备状态</label>
                                <label class="select">
                                    <select name="" id="" ng-model="editdata.status_tag" required="required">
                                        <option value="生效">生效</option>
                                        <option value="失效">失效</option>
                                    </select>
                                </label>
                            </section>
                            <!-- <section class="col-sm-5" style="margin: 0 20px 15px;">
                                <label class="label">备注</label>
                                <label class="input">
                                    <input type="text" maxlength="50" required="required" ng-model="editdata.remarks">
                                </label>
                            </section> -->
                        </fieldset>

                        <footer>

                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                关闭
                            </button>
                            <button type="submit" class="btn btn-primary">
                                提交
                            </button>

                        </footer>
                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->


    <div class="modal fade" id="setDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">参数设置</h4>
                </div>
                <div class="modal-body">

                    <form id="smart-form-register" class="smart-form" data-smart-registration-form ng-submit="setParameters()">
                        <fieldset class="row">

                             <section class="col-sm-11" style="margin: 0 20px 15px;">
                                
                                <label class="checkbox-inline">
                                    <input type="checkbox" ng-model="parametercheck.col_cycle" ng-model="parametercheck.col_cycle">
                                     采集间隔时间(秒)
                                 </label>
                                <label class="input">
                                    <input type="number" maxlength="50" ng-model="parameters.col_cycle">
                                </label>
                            </section>

                            <section class="col-sm-11" style="margin: 0 20px 15px;">
                                <label class="checkbox-inline">
                                    <input type="checkbox" ng-model="parametercheck.warn_up" ng-model="parametercheck.warn_up">
                                   报警上限
                                </label>
                                <label class="input">
                                    <input type="number" maxlength="50" ng-model="parameters.warn_up">
                                </label>
                            </section>
                            <section class="col-sm-11" style="margin: 0 20px 15px;">
                                <label class="checkbox-inline">
                                    <input type="checkbox" ng-model="parametercheck.warn_down">
                                    报警下限
                                </label>
                                <label class="input">
                                    <input type="number" maxlength="50" ng-model="parameters.warn_down">
                                </label>
                            </section>
                            
                        </fieldset>

                        <footer>

                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                关闭
                            </button>
                            <button type="submit" class="btn btn-primary" ng-show="device_manage">
                                发送
                            </button>

                        </footer>
                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <div class="modal fade" id="queryDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        ×
                    </button>
                    <h4 class="modal-title">信息</h4>
                </div>
                <div class="modal-body">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th style="width:50%">名字</th>
                                <th style="width:50%">数据</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>采集间隔时间</td>
                                <td><span class="badge">{{realdata.col_cycle}}</span></td>
                            </tr>
                            <tr>
                                <td>信号强度</td>
                                <td><span class="badge bg-color-darken">{{realdata.sig}}</span></td>
                            </tr>
                            <tr>
                                <td>手机号码</td>
                                <td><span class="badge bg-color-greenLight">{{realdata.sim}}</span></td>
                            </tr>
                            <tr>
                                <td>压力</td>
                                <td><span class="badge bg-color-blueLight">{{realdata.press}}</span></td>
                            </tr>
                            <tr>
                                <td>最小量程</td>
                                <td><span class="badge bg-color-orange">{{realdata.minvalue}}</span></td>
                            </tr>
                            <tr>
                                <td>最大量程</td>
                                <td><span class="badge bg-color-darken">{{realdata.maxvalue}}</span></td>
                            </tr>
                            <tr>
                                <td>报警上限</td>
                                <td><span class="badge bg-color-greenLight">{{realdata.warn_up}}</span></td>
                            </tr>
                            <tr>
                                <td>报警下限</td>
                                <td><span class="badge bg-color-blueLight">{{realdata.warn_down}}</span></td>
                            </tr>
                            <tr>
                                <td>电池电压</td>
                                <td><span class="badge bg-color-orange">{{realdata.vol}}</span></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <button type="button" class="btn btn-primary" ng-click="querydevice()">
                        下发查询
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
    <div class="modal fade" id="showDelDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        ×
                    </button>
                    <h4 class="modal-title">信息</h4>
                </div>
                <div class="modal-body">
                    <p>
                        您确实要删除这个传感器吗？
                    </p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <button type="button" class="btn btn-primary" ng-click="deldevice()">
                        删除传感器
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->

    <div class="modal fade" id="bind" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p>
                        是否绑定该设备到该项目？
                    </p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        取消
                    </button>
                    <button type="button" class="btn btn-primary" ng-click="bind()">
                        确认
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div>
</div>
